package com.gitee.qdbp.general.common.biz.event.service;

import java.util.List;
import com.gitee.qdbp.able.exception.ServiceException;
import com.gitee.qdbp.general.common.api.event.enums.Operate;
import com.gitee.qdbp.general.common.api.event.enums.Pointer;
import com.gitee.qdbp.general.common.api.event.service.IEventTrigger;

public class EventTrigger implements IEventTrigger {

    private EventCenter center;

    public EventTrigger(EventCenter center) {
        this.center = center;
    }

    @Override
    public void beforeCreate(String dataType, Object object) throws ServiceException {
        center.trigger(dataType, Operate.CREATE, Pointer.BEFORE, object);
    }

    @Override
    public void afterCreate(String dataType, Object object) throws ServiceException {
        center.trigger(dataType, Operate.CREATE, Pointer.AFTER, object);
    }

    @Override
    public void beforeCreate(String dataType, List<?> object) throws ServiceException {
        center.trigger(dataType, Operate.CREATE, Pointer.BEFORE, object);
    }

    @Override
    public void afterCreate(String dataType, List<?> object) throws ServiceException {
        center.trigger(dataType, Operate.CREATE, Pointer.AFTER, object);
    }

    @Override
    public void beforeUpdate(String dataType, Object object) throws ServiceException {
        center.trigger(dataType, Operate.UPDATE, Pointer.BEFORE, object);
    }

    @Override
    public void afterUpdate(String dataType, Object object) throws ServiceException {
        center.trigger(dataType, Operate.UPDATE, Pointer.AFTER, object);
    }

    @Override
    public void beforeDelete(String dataType, Object object) throws ServiceException {
        center.trigger(dataType, Operate.DELETE, Pointer.BEFORE, object);
    }

    @Override
    public void afterDelete(String dataType, Object object) throws ServiceException {
        center.trigger(dataType, Operate.DELETE, Pointer.AFTER, object);
    }

}
